# coding=utf-8
import tushare as ts
import threading


class TUShareObject:
    _instance_lock = threading.Lock()
    
    def __init__(self):
        self.__refresh_token()

    def __refresh_token(self):
        ts.set_token('8e0e2afe2578af38a4b1eed34c73baab575d0ed27b1c8d604314ea62')

    # @staticmethod
    def __tushare_apiobject(self):
        return ts.pro_api()

    # @staticmethod
    def __tushare_object(self):
        return ts
    
    @classmethod
    def instance(cls):
        if not hasattr(TUShareObject, "_instance"):
            with TUShareObject._instance_lock:
                if not hasattr(TUShareObject, "_instance"):
                    TUShareObject._instance = TUShareObject()
        return TUShareObject._instance.__tushare_apiobject()

    @classmethod
    def origin_instance(cls):
        if not hasattr(TUShareObject, "_instance"):
            with TUShareObject._instance_lock:
                if not hasattr(TUShareObject, "_instance"):
                    TUShareObject._instance = TUShareObject()
        return TUShareObject._instance.__tushare_object()
